$(function(){
	$("#follow").click(follow);
	$("#expertBtn").click(expertBtn);
	$("#forbidden").click(forbidden);
});

function follow() {
	var btn = this;
	if($(btn).hasClass("btn-info")) {
		// 关注TA
		$.post(
			CONTEXT_PATH + "/follow",
			{"entityType":3,"entityId":$(btn).prev().val()},
			function(data) {
				data = $.parseJSON(data);
				if(data.code == 0) {
					window.location.reload();
				} else {
					alert(data.msg);
				}
			}
		);
		// $(btn).text("已关注").removeClass("btn-info").addClass("btn-secondary");
	} else {
		// 取消关注
		$.post(
			CONTEXT_PATH + "/unfollow",
			{"entityType":3,"entityId":$(btn).prev().val()},
			function(data) {
				data = $.parseJSON(data);
				if(data.code == 0) {
					window.location.reload();
				} else {
					alert(data.msg);
				}
			}
		);
		//$(btn).text("关注TA").removeClass("btn-secondary").addClass("btn-info");
	}
}

function expertBtn() {
	$.post(
		CONTEXT_PATH + "/data/authority",
		{
			"userId": $("#entityId").val(),
			"type": 1
		},
		function (data) {
			data = $.parseJSON(data);
			if (data.code == 0) {
				$("#expertBtn").attr("disabled", "disabled");
			}else{
				alert(data.msg);
			}
		}
	);
}

function forbidden() {
	$.get(
		CONTEXT_PATH + "/user/changeStatus",
		{
			"userId": $("#entityId").val(),
		}
	);
}